home *** CD-ROM | disk | FTP | other *** search
/ Enter 2006 February / enter-2006-02.iso / files / Illustrator_CS2_ue_TryOut.exe / bridge / Adobe Bridge 1.0.msi / Data1.cab / _4VariablesPane.jsx < prev    next >
Encoding:
Text File  |  2005-03-24  |  7.6 KB  |  254 lines

  1. /**************************************************************************
  2. *
  3. *  @@@BUILDINFO@@@ 34variablesPane.jsx 1.0.0.49 07-Feb-2005
  4. *  Copyright 2005 Adobe Systems Incorporated
  5. *  All Rights Reserved.
  6. *
  7. * NOTICE:  All information contained herein is, and remains the property of
  8. * Adobe Systems Incorporated  and its suppliers,  if any.  The intellectual 
  9. * and technical concepts contained herein are proprietary to  Adobe Systems 
  10. * Incorporated  and its suppliers  and may be  covered by U.S.  and Foreign 
  11. * Patents,patents in process,and are protected by trade secret or copyright 
  12. * law.  Dissemination of this  information or reproduction of this material
  13. * is strictly  forbidden  unless prior written permission is  obtained from 
  14. * Adobe Systems Incorporated.
  15. **************************************************************************/
  16.  
  17. // Code to add to the Local Variables pane
  18. // The output field of the variables pane is a tree view, but since ScriptUI
  19. // does not support tree views yet, the interface is at the pane itself.
  20.  
  21. // Setup the pane. If config.jsx defined configuration data, then convert
  22. // property names to the form used as path names: a.b => $.global["a]["b"]
  23. // The property "default" may contain either "include" or "exclude".
  24.  
  25. // used properties:
  26. // target - the current target
  27. // engine - the current engine
  28. // scope  - the JS scope
  29.  
  30. window.variables.setup = function()
  31. {
  32.     function convertPath (prop)
  33.     {
  34.         if (prop == "default")
  35.             return prop;
  36.  
  37.         // convert a.b.c to $.global["a"]["b"]["c"]
  38.         var parts = prop.split ('.');
  39.         var path = '$.global';
  40.         for (var i = 0; i < parts.length; i++)
  41.             path += '["' + parts [i] + '"]';
  42.         return path;
  43.     }
  44.  
  45.     if (!this.config)
  46.         this.config = {};
  47.  
  48.     var configAll = this.config ["all"];
  49.     for (var target in this.config)
  50.     {
  51.         if (target == "all")
  52.             continue;
  53.  
  54.         var targetObj = this.config [target];
  55.         var newTargetObj = {};
  56.         // merge in the "all" object if present
  57.         if (configAll)
  58.         {
  59.             for (var prop in configAll)
  60.                 newTargetObj [convertPath (prop)] = configAll [prop];
  61.         }
  62.         // make sure that we have a default
  63.         if (!newTargetObj ["default"])
  64.             newTargetObj ["default"] = "include";
  65.  
  66.         // now merge in all the others that we found
  67.         for (var prop in targetObj)
  68.         {
  69.             // this property contains whether to include or to exclude data by default
  70.             var value = (targetObj [prop] == "exclude") ? "exclude" : "include";
  71.             newTargetObj [convertPath (prop)] = value;
  72.         }
  73.         this.config [target] = newTargetObj;
  74.     }
  75. }
  76.  
  77. // Get all variables for a specific stack scope.
  78.  
  79. window.variables.getVariables = function (target, engine, scope, all)
  80. {
  81.     this.target = target;
  82.     this.engine = engine;
  83.     if (scope.length)
  84.         this.scope  = scope;
  85.     else if (this.scope == undefined)
  86.         this.scope = "$.global";
  87.     // pass functions in - we ask for a workspace
  88.     var bt = this._createMessage (prefs.showFunctions);
  89.     if (all)
  90.     {
  91.         bt.headers.All = "1";
  92.         this.clear();
  93.     }
  94.     bt.safeSend();
  95. }
  96.  
  97. // Refresh the entire display.
  98.  
  99. window.variables.refresh = function()
  100. {
  101.     this.clear();
  102.     // pass functions in - we ask for a workspace
  103.     var bt = this._createMessage (prefs.showFunctions);
  104.     bt.safeSend();
  105. }
  106.  
  107. // The callback if the user typed in a new value.
  108.  
  109. window.variables.onChanged = function (path, value)
  110. {
  111.     var ok = Document.checkSyntax (value);
  112.     if (ok != true)
  113.     {
  114.         app.beep();
  115.         window.statusLine = ok;
  116.     }
  117.     else
  118.         // eval the expression, but do not print the reply
  119.         currentDebugger.eval (path + '=' + value, true);
  120. }
  121.  
  122. // The callback for the Expand event.
  123.  
  124. window.variables.onExpand = function (path, readOnly, name, value)
  125. {
  126.     var bt = this._createMessage (prefs.showMethods);
  127.     bt.body = path;
  128.     bt.varName = name;
  129.     bt.varValue = value;
  130.     bt.onOwnError = function (bt)
  131.     {
  132.         window.variables.setInvalid (this.body, this.varName, this.varValue);
  133.     }
  134.     bt.safeSend();
  135. }
  136.  
  137. // Helper method. Create and initialize a BridgeTalk message.
  138.  
  139. window.variables._createMessage = function (doFunctions)
  140. {
  141.     var bt = BridgeTalk.create (this.target, "Variables");
  142.     bt.headers.Engine = this.engine;
  143.     // create the setting for things to exclude
  144.     bt.headers.Exclude = "xxx";
  145.     if (!prefs.showPredefined)
  146.         bt.headers.Exclude += ",builtin";
  147.     if (!doFunctions)
  148.         bt.headers.Exclude += ",Function";
  149.  
  150.     bt.onOwnResult = function (bt)
  151.     {
  152.         window.variables._readReply (bt, this.body);
  153.     }
  154.     bt.body = this.scope;
  155.  
  156.     return bt;
  157. }
  158.  
  159. // Helper method: Interpret the incoming BridgeTalk message body and update the variables.
  160.  
  161. window.variables._readReply = function (bt, basePath)
  162. {
  163.     this.clear (basePath);
  164.     // get the exclusion object
  165.     var target = bt.sender.split ('-') [0];
  166.     var config = window.variables.config [target];
  167.     if (!config)
  168.         config = { "default":"include" };
  169.  
  170.     // Update the display. The BridgeTalk instance contains the data. Each body line has 4 elements,
  171.     // the data type, the variable name, the variable value, and a read-only indicator.
  172.  
  173.     var i, reply = bt.splitBody();
  174.     // update all existing items, create a new one if needed
  175.     for (i = 0; i < reply.length; i++)
  176.     {
  177.         // The line has four elements.
  178.         var dataType = reply [i][0];
  179.         var name     = reply [i][1];
  180.         var value    = reply [i][2];
  181.         var readonly = reply [i][3];
  182.         var isObject = false;
  183.  
  184.         var path;
  185.         if (basePath == "")            // local workspace: syntax of names should be OK
  186.             path = name;
  187.         else                            // other: better use bracket notation
  188.             path = basePath + '["' + app.escape (name) + '"]';
  189.  
  190.         // If the line is an invalid object, the data type is "invalid classname"
  191.         var valid = dataType.substr (0, 8) != "invalid ";
  192.         if (!valid)
  193.             dataType = dataType.substr (8);
  194.  
  195.         switch (dataType)
  196.         {
  197.             case "deleted":        this.remove (path);
  198.                                 path = undefined;                    break;
  199.             case "undefined":    value = undefined;                    break;
  200.             case "null":        value = null;                        break;
  201.             case "boolean":        value = (value == "true");            break;
  202.             case "number":        value = parseFloat (eval (value));    break;
  203.             case "string":        if (typeof value == "undefined")
  204.                                     value = "";                        break;
  205.             case "Function":    // a function may be defined in several ways:
  206.                                 // Function,foo,foo()   defined as function foo(){}
  207.                                 // Function,foo,()      defined as foo = function()
  208.                                 // Function,bar,foo()   defined as bar = foo
  209.                                 value = "function " + value; 
  210.                                 isObject = true;
  211.                                 break;
  212.             case "EnumError":    // On an enumeration error, strip the EnumError: prefix
  213.                                 // and create an Error object (the update()
  214.                                 // method knows how to deal with it)
  215.                                 var index = value.indexOf (': ');
  216.                                 if (index > 0)
  217.                                     value = value.substr (index + 2);
  218.                                 value = new Error (value);
  219.                                 break;
  220.             default:            isObject = valid;
  221.                                 // show the class if the value does not start with '['
  222.                                 if (typeof value == "undefined")
  223.                                     value = '[' + dataType + ']';
  224.                                 else if (value.length && value[0] != '[')
  225.                                     value = '[' + dataType + '] ' + value;
  226.         }
  227.         if (path)
  228.         {
  229.             var include = config [path];
  230.             if (!include)
  231.                 include = config ["default"];
  232.             if (include == "include")
  233.             {
  234.                 if (valid)
  235.                     this.update (path, name, value, isObject, (readonly == "true"));
  236.                 else
  237.                     this.setInvalid (path, name, "[object " + dataType + "]");
  238.                 // recursive call for open objects
  239.                 if (isObject && this.isOpen (path))
  240.                 {
  241.                     // pass methods in - we ask for an object
  242.                     var nextBT = this._createMessage (prefs.showMethods);
  243.                     nextBT.body = path;
  244.                     nextBT.safeSend();
  245.                 }
  246.             }
  247.         }
  248.     }
  249. }
  250.  
  251. // set up the pane
  252.  
  253. window.variables.setup();
  254.